package kz.kstu.scantest.desktop.report;

import kz.kstu.scantest.business.entity.data.FormData;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperPrint;
import org.apache.log4j.Logger;

import javax.imageio.ImageIO;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author Filipp_Stankevich
 *         created: 20.09.11 19:39
 */
public abstract class AbstractFormDataReport {

   private static final Logger LOGGER = Logger.getLogger(AbstractFormDataReport.class);

    public final static String LOGO_REPORT_FILE = "reports/logo.jpg";

    public abstract JasperPrint buildReport(List<FormData> formDataList) throws JRException;

    public static AbstractFormDataReport getInstance(FormDataReportEnum formDataReportEnum) {
        switch (formDataReportEnum) {
            case ANSWER_REPORT :
                return new AnswerFormDataReport();
            case ANALYZE_REPORT:
                return new AnalyzeFormDataReport();
            default:
                throw new IllegalArgumentException("Неизвестный тип отчета");
        }
    }

    protected Image getLogoImage() {
        ClassLoader classLoader = AbstractFormDataReport.class.getClassLoader();
        InputStream logoInputStream = classLoader.getResourceAsStream(LOGO_REPORT_FILE);
        Image image = null;
        try {
            image = ImageIO.read(logoInputStream);
        } catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
        }
        return image;
    }
}
